#include<bits/stdc++.h>
using namespace std;
int a[10000];
int main()
{
	long long n,i=0,j,baoshu=0,out=0;
	cin>>n;
	while(out<=n-1)
	{
		if(!a[i])					//a[i]==0
		{
			baoshu=(baoshu+1)%3;	//baoshu++,baoshu=baoshu%3
			if(baoshu==0)
			out++,a[i]=1;
		}
		i=(i+1)%n;
	}
	cout<<i;
    return 0;
}
